﻿package lobby
{
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import lobby.events.LobbyEvent;
	import lobby.GlobalVariables;
	import lobby.exchangeddata.HashTable;
	import lobby.events.LobbyEvent;
	
	/**
	 * ...
	 * @author David
	 */
	public class MenuHolder extends MovieClip
	{
		public var label_arr:Array = new Array();
		public var index_arr:Array = new Array();
		public var menu:menuBg;
		private var flagCreate:Boolean = true;
		private var item:MovieClip;
		
		public function MenuHolder()
		{
		}
		
		public function initTextName()
		{
			trace("menu inittext : " +GlobalVariables.showTransfer);
			//GlobalVariables.showTransfer = "false";
			//GlobalVariables.hidePassword = "true";
			
			index_arr = new Array("accountInfoBtn", "transactionReportBtn", "trasferReportBtn", "betStatusBtn", "gameHistoryBtn", "gameRuleBtn", "supportBtn");
			label_arr = new Array(GlobalVariables.langInfo.hashTable.lookupString("MNAccountInfo"), 
								  GlobalVariables.langInfo.hashTable.lookupString("MNTransactionReport"), 
								  GlobalVariables.langInfo.hashTable.lookupString("MNTransferReport"), 
								  GlobalVariables.langInfo.hashTable.lookupString("MNbetstatus"), 
								  GlobalVariables.langInfo.hashTable.lookupString("MNgamehistory"), 
								  GlobalVariables.langInfo.hashTable.lookupString("MNgamerule"), 
								  GlobalVariables.langInfo.hashTable.lookupString("MNhotline")); 
			
			
			//check show showTransfer
			if (GlobalVariables.showTransfer == "false") {
				var indexTransfer:int = index_arr.indexOf("trasferReportBtn");
				index_arr.splice(indexTransfer,1);
				label_arr.splice(indexTransfer,1);
			}
			//check show accountInfo
			if (GlobalVariables.hidePassword == "true") {
				var indexAccountInfo:int = index_arr.indexOf("accountInfoBtn");
				index_arr.splice(indexAccountInfo,1);
				label_arr.splice(indexAccountInfo,1);
			}
			/////////////////////////////////////
			if (flagCreate == true)
			{
				flagCreate = false;
				init(index_arr.length);
			}
			else
			{
				for (var i = 0; i < index_arr.length; i++)
				{
					trace(typeof(this.getChildByName(index_arr[i])));
					var _mc:MovieClip = MovieClip(this.getChildByName(index_arr[i]));
					_mc.text_txt.text = label_arr[i];
				}
			}
		}
		
		public function initText()
		{
		
		}
		
		public function init(num)
		{
			//menu.removeMovieClip();
			menu = new menuBg();
			menu.child_mc.height = num * 30;
			menu.x = 0;
			menu.y = 0;
			menu.child_mc.addEventListener(MouseEvent.ROLL_OVER, menuOverHdl);
			menu.child_mc.addEventListener(MouseEvent.ROLL_OUT, menuOutHdl);
			createMenuItem(num);
			
			addChild(menu);
			this.setChildIndex(menu, 0);
		}
		
		public function menuOverHdl(e:MouseEvent):void
		{
			this.visible = true;
		}
		
		public function menuOutHdl(e:MouseEvent):void
		{
			this.visible = false;
		}
		
		public function createMenuItem(num)
		{
			//trace("num : " + num);
			var pos:Number = 0;
			/*for (var j = 0; j<num; j++) {
			   this["menu"+j].removeMovieClip();
			 }*/
			for (var i = 0; i < num; i++)
			{
				//trace("i : "+i)
				item = MovieClip(new itemMenu());
				item.text_txt.text = label_arr[i];
				item.x = 1;
				if (i == 0)
				{
					item.y = 0;
				}
				else
				{
					item.y = pos;
				}
				pos += 30;
				item.name = index_arr[i];
				item.text_txt.mouseEnabled = false;
				item.buttonMode = true;
				item.addEventListener(MouseEvent.ROLL_OVER, itemOverHdl);
				item.addEventListener(MouseEvent.ROLL_OUT, itemOutHdl);
				item.addEventListener(MouseEvent.CLICK, menuClickHdl);
				addChild(item);
			}
			this.tabChildren = false;
		}
		
		public function itemOverHdl(e:MouseEvent):void
		{
			this.visible = true;
			//e.currentTarget.gotoAndStop(2);
			e.currentTarget.text_txt.textColor = 0xEFE601;
			//trace("t : " + e.currentTarget.name);
		}
		
		public function itemOutHdl(e:MouseEvent):void
		{
			this.visible = false;
			//e.currentTarget.gotoAndStop(1);
			e.currentTarget.text_txt.textColor = 0xFFFFFF;
		}
		
		public function menuClickHdl(e:MouseEvent):void
		{
			this.visible = false;
			//trace("anem:" + e.currentTarget.name);
			
			//kkhai			
			var event:LobbyEvent = new LobbyEvent(LobbyEvent.SET_MENU_GAME, true);
			trace("e.currentTarget.name : " + e.currentTarget.name);
			event.ms = e.currentTarget.name;
			dispatchEvent(event);
		}
	}

}
